<script setup lang="ts">
import { reactive, ref } from "vue";
import { countDeviceNum,getDevData } from "@/api";
import CountUp from "@/components/count-up";
import {ElMessage} from "element-plus"



const tooltip = reactive({
  show: false,
  text: "",
  x: 0,
  y: 0,
});

// 显示悬浮提示
const showTooltip = (text: string, x: number, y: number) => {
  tooltip.text = text;
  tooltip.x = x;
  tooltip.y = y;
  tooltip.show = true;
};

// 隐藏悬浮提示
const hideTooltip = () => {
  tooltip.show = false;
};





const duration = ref(2);
const state = reactive({
  deviceTotalNum: 0,
  placeTotalNum: 0,
  deviceUseNum: 0,
 memberTotalNum :0,
});


const getDatareal = async () => {
      const res = await getDevData()
      state.deviceTotalNum = res.data.deviceTotalNum;
      state.placeTotalNum = res.data.placeTotalNum;
      state.deviceUseNum = res.data.deviceUseNum;
      state.memberTotalNum = res.data.memberTotalNum;

      console.log('获取设备总览',res)
  
}
getDatareal()



</script>

<template>
  <ul class="user_Overview flex">
    <li class="user_Overview-item" style="color: #00fdfa"  @mouseenter="showTooltip(`在线设备总数：${state.deviceTotalNum}`, $event.clientX, $event.clientY)"
      @mouseleave="hideTooltip">
      <div class="user_Overview_nums allnum"  :title="`在线设备总数：${state.deviceTotalNum}`">
        <CountUp :endVal="state.deviceTotalNum" :duration="duration" />
      </div>
      <p>在线设备总数</p>
    </li>
    <li class="user_Overview-item" style="color: #07f7a8"  @mouseenter="showTooltip(`站点总数：${state.placeTotalNum}`, $event.clientX, $event.clientY)"
      @mouseleave="hideTooltip">
      <div class="user_Overview_nums online">
        <CountUp :endVal="state.placeTotalNum" :duration="duration" />
      </div>
      <p>站点总数</p>
    </li>
    <li class="user_Overview-item" style="color: #e3b337"   @mouseenter="showTooltip(`正在使用中的设备：${state.deviceUseNum}`, $event.clientX, $event.clientY)"
      @mouseleave="hideTooltip">
      <div class="user_Overview_nums offline">
        <CountUp :endVal="state.deviceUseNum" :duration="duration" />
      </div>
      <p>正在使用中的设备</p>
    </li>
    <li class="user_Overview-item" style="color: #f5023d"  @mouseenter="showTooltip(`会员总数：${state.memberTotalNum}`, $event.clientX, $event.clientY)"
      @mouseleave="hideTooltip" >
      <div class="user_Overview_nums laramnum">
        <CountUp :endVal="state.memberTotalNum" :duration="duration" />
      </div>
      <p>会员总数</p>
    </li>


     <div 
      v-if="tooltip.show" 
      class="custom-tooltip" 
      :style="{ left: `${tooltip.x + 10}px`, top: `${tooltip.y + 10}px` }"
    >
      {{ tooltip.text }}
    </div>
  </ul>
</template>

<style scoped lang="scss">


.custom-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 9999;
}

.left-top {
  width: 100%;
  height: 100%;
}

.user_Overview {
  li {
    flex: 1;

    p {
      text-align: center;
      height: 16px;
      font-size: 16px;
    }

    .user_Overview_nums {
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 50px auto 30px;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }

    .allnum {
      &::before {
        background-image: url("@/assets/img/left_top_lan.png");
      }
    }

    .online {
      &::before {
        background-image: url("@/assets/img/left_top_lv.png");
      }
    }

    .offline {
      &::before {
        background-image: url("@/assets/img/left_top_huang.png");
      }
    }

    .laramnum {
      &::before {
        background-image: url("@/assets/img/left_top_hong.png");
      }
    }
  }
}
</style>
